package org.to_zero.springboot.springbootquick.config;

import io.swagger.annotations.ApiOperation;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import springfox.documentation.builders.ApiInfoBuilder;
import springfox.documentation.builders.PathSelectors;
import springfox.documentation.builders.RequestHandlerSelectors;
import springfox.documentation.service.ApiInfo;
import springfox.documentation.service.Contact;
import springfox.documentation.spi.DocumentationType;
import springfox.documentation.spring.web.plugins.Docket;
import springfox.documentation.swagger2.annotations.EnableSwagger2;

@Configuration
@EnableSwagger2
public class SwaggerConfig {

    @Bean
    public Docket createRestApi() {
        return new Docket(DocumentationType.SWAGGER_2)
                .groupName("")
                .select()// 选择哪些路径和API会生成document
                .apis(RequestHandlerSelectors.withMethodAnnotation(ApiOperation.class))// 对所有api进行监控
                .paths(PathSelectors.any())// 对所有路径进行监控
                .build()
                .apiInfo(apiInfo());
    }

    /**
     * 创建改API的基本信息（这些基本信息会展示在文档页面中）
     * 访问地址： http://项目实际地址/swagger-ui.html
     *
     * @return
     */
    private ApiInfo apiInfo() {
        return new ApiInfoBuilder()
                .title("springboot快速上手")
                .description("学习使用")
                .contact(new Contact("moonholder","https://gitee.com/moonholder","yukiralink@mail.com"))
                .termsOfServiceUrl("http://localhost:80/swagger-ui.html")// 将“url”换成自己的ip:port
                .version("2.0")
                .build();
    }
}